package com.bmatch.yikaowx.web.dao;

import com.bmatch.yikaowx.web.dataobject.User;

import java.util.List;

import org.apache.ibatis.annotations.*;
import org.apache.ibatis.type.JdbcType;

@Mapper
public interface UserMapper {
    @Delete({
            "delete from zr_examiner_user",
            "where id = #{id,jdbcType=BIGINT}"
    })
    int deleteByPrimaryKey(Long id);

    @Insert({
            "insert into zr_examiner_user (mobile, ",
            "name, pwd, gmt_created, ",
            "gmt_modified)",
            "values (#{mobile,jdbcType=VARCHAR}, ",
            "#{name,jdbcType=VARCHAR}, #{pwd,jdbcType=VARCHAR}, now(), ",
            "now())"
    })
    int insert(User record);

    @Select({
            "select",
            "id, mobile, name, pwd, gmt_created, gmt_modified",
            "from zr_examiner_user",
            "where id = #{id,jdbcType=BIGINT}"
    })
    @Results(id = "mobileMapper", value = {
            @Result(column = "id", property = "id", jdbcType = JdbcType.BIGINT, id = true),
            @Result(column = "mobile", property = "mobile", jdbcType = JdbcType.VARCHAR),
            @Result(column = "name", property = "name", jdbcType = JdbcType.VARCHAR),
            @Result(column = "pwd", property = "pwd", jdbcType = JdbcType.VARCHAR),
            @Result(column = "gmt_created", property = "gmtCreated", jdbcType = JdbcType.TIMESTAMP),
            @Result(column = "gmt_modified", property = "gmtModified", jdbcType = JdbcType.TIMESTAMP)
    })
    User selectByPrimaryKey(Long id);

    @Select({
            "select",
            "id, mobile, name, pwd, gmt_created, gmt_modified",
            "from zr_examiner_user",
            "where name like CONCAT('%',#{keyword},'%') "
    })
    @ResultMap("mobileMapper")
    List<User> selectByKeyWord(@Param("keyword") String keyword);

    @Select({
            "select",
            "id, mobile, name, pwd, gmt_created, gmt_modified",
            "from zr_examiner_user",
            "where mobile = #{mobile}"
    })
    @ResultMap("mobileMapper")
    User queryUser(@Param("mobile") String mobile);

    @Select({
            "select",
            "id, mobile, name, pwd, gmt_created, gmt_modified",
            "from zr_examiner_user"
    })
    @Results({
            @Result(column = "id", property = "id", jdbcType = JdbcType.BIGINT, id = true),
            @Result(column = "mobile", property = "mobile", jdbcType = JdbcType.VARCHAR),
            @Result(column = "name", property = "name", jdbcType = JdbcType.VARCHAR),
            @Result(column = "pwd", property = "pwd", jdbcType = JdbcType.VARCHAR),
            @Result(column = "gmt_created", property = "gmtCreated", jdbcType = JdbcType.TIMESTAMP),
            @Result(column = "gmt_modified", property = "gmtModified", jdbcType = JdbcType.TIMESTAMP)
    })
    List<User> selectAll();

    @Update({
            "update zr_examiner_user",
            "set mobile = #{mobile,jdbcType=VARCHAR},",
            "name = #{name,jdbcType=VARCHAR},",
            "pwd = #{pwd,jdbcType=VARCHAR},",
            "gmt_modified = now()",
            "where id = #{id,jdbcType=BIGINT}"
    })
    int updateByPrimaryKey(User record);

}